package com.example.idemfactor.sdk.config;

import com.example.idemfactor.sdk.annotations.Idemfactor;
import com.example.idemfactor.sdk.aspect.IdemInterceptor;
import org.springframework.aop.support.DefaultPointcutAdvisor;
import org.springframework.aop.support.annotation.AnnotationMatchingPointcut;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.annotation.Order;

@Order(-1)
@Configuration
// 开启AOP代理自动配置
// @EnableAspectJAutoProxy(exposeProxy = true)
@ComponentScan(
        basePackages = {
                "com.example.idemfactor.sdk.handler"
        }
)
public class IdemfactorConfig {
        @Bean
        public DefaultPointcutAdvisor defaultPointcutAdvisor() {
                // 配置注解切点
                AnnotationMatchingPointcut pointcut = new AnnotationMatchingPointcut(null, Idemfactor.class);

                // 配置增强类advisor
                DefaultPointcutAdvisor advisor = new DefaultPointcutAdvisor();
                advisor.setPointcut(pointcut);
                advisor.setAdvice(idemInterceptor());
                return advisor;
        }

        @Bean
        public IdemInterceptor idemInterceptor() {
                IdemInterceptor interceptor = new IdemInterceptor();
                return interceptor;
        }
}
